<%--
	author:daniel.yan
	time:2012/4/22 12:09:13
--%>

<%@page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib uri="TowkerTagLib" prefix="rbac"%>
<%@include file="/commons/include/html_doctype.html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>添加</title>
	<%@include file="/commons/include/add.jsp" %>
    <link rel="stylesheet" href="${ctx}/js/jquery/ui/css/jquery-ui.css" />
    <script src="${ctx}/js/jquery/ui/jquery-ui.js"></script>
    <script src="${ctx}/js/jquery/ui/jquery.ui.combobox.js"></script>
    <script type="text/javascript" src="${ctx}/js/calendar/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
$(function(){
	$("#dataFormSave").unbind("click");
	$("#dataFormSave").click(function()
	{
		$('input[name*="amount"]').each(function(){
			$(this).rules("add", {
						  required: true,
						  number:true ,
						  messages: { required: "请填写", number:"请填写数字"}
						  });
		});
		$("#dataForm").submit();
	});
	
	jQuery("#dataForm").validate(
	{
		rules: {
			custom_code:{
				required: true
			},
			create_date:{
				required: true
			},
			submit_date:{
				required: true
			}
		},
		messages: {
			custom_code:{
				required: "请填写客户代码"
			},
			create_date:{
				required: "请选择制单日期"
			},
			submit_date:{
				required: "请选择提交日期"
			}
		},
		submitHandler:function(form)
		{
			setGoodsInfo();
			jQuery(form).ajaxSubmit(_options);
		}
	});
	<c:if test="${loginUser.userNature == 1}">	
	$("#custom_code").combobox();
	</c:if>
});
_callback = function() {
	location.href = ctx + "/manage/sell/getOrder.htm";
}
validCallBack = function()
{
	if($("#goodsInfo").val() == "") {
		alert("请选择产品!");
		return false;
	}
	return true;
};
function setGoodsInfo() {
	var goodsInfoStr = "";
	//添加页面自定义校验
	for(var id in goods) {
		goodsInfoStr += id + ",";
	}
	//alert(goodsInfoStr);
	$("#goodsInfo").attr("value", goodsInfoStr);
}
var goods = {};
//JavaScript Document
function selectGoods() {
	//showModelessDialog
	//encodeURI、encodeURIComponent
	var source = encodeURIComponent(ctx+"/manage/basicData/selectGoods.htm?typeid=&classId=&r=" + Math.random());
	var url = ctx + "/commons/showDialog.jsp?r=" + Math.random() + "&url=" + source;
	var result = window.showModalDialog(url, this, "dialogWidth=600px;dialogHeight=600px;scroll=no");
	var panel = $("#MGoodsPanel");
	var html = "";
	for(var i = 0; i < result.length; i++) {
		var v = result[i];
		if(typeof(goods[v.id]) == "undefined" || goods[v.id] == null) {
			goods[v.id] = v.sn;
			html += '    <TBODY><tr>'
				+ '      <td>' + v.sn + '<input type="hidden" name="wprice_' + v.id + '" id="wprice_' + v.id + '" value="' + v.wprice + '"  /></td>'
				+ '      <td>' + v.name + '</td>'
				+ '      <td>' + v.weight + '</td>'
				+ '      <td>' + v.unit + '</td>'
				+ '      <td><input name="amount_' + v.id + '" type="text" id="amount_' + v.id + '" value="0" size="10"  /></td>'
				+ '      <td><a href="#" onClick="deleteGoods(this, ' + v.id + ')">删除</a></td>'
				+ '    </tr>';
		}
	}
	html = html + '</TBODY>';
	panel.append(html);
}
function deleteGoods(el, id) {
	if(confirm("确定要删除吗？")) {
		var row = $(el).parent().parent();
	row.remove();
	goods[id] = null;
	delete goods[id];
	}
}
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="listLogo">
	<tr>
		<td class="title">下订单</td>
		<td>
			<div class="menuTool">
				<a class="save" id="dataFormSave" href="#">保存</a>
				<a class="back" href="getOrder.htm">返回</a>
			</div>
		</td>
	</tr>
</table>
<div class="line"></div>
<form id="dataForm" method="post" action="addOrder2.htm">
<input type="hidden" name="goodsInfo" id="goodsInfo" value="" />
<table border="0" cellspacing="1" cellpadding="0" class="listTable">
	<tr>
		<td class="form_title">客户代码：</td>
		<td class="form_input">
          <c:choose>            
		  <c:when test="${loginUser.userNature == 2}">	
          ${custom_code}<input type="hidden" id="custom_code" name="custom_code" value="${custom_code}" />
          </c:when>
          <c:otherwise>
		  <select name="custom_code" id="custom_code">
          <c:forEach items="${customCodes}" var="d" varStatus="status">
          <option value="${d.custom_code}">${d.custom_name}[${d.custom_code}]</option>
          </c:forEach>
          </select>
          </c:otherwise>
          </c:choose>  
        </td>
	</tr>
	<tr>
		<td class="form_title">制单日期：</td>
		<td class="form_input"><input type="text" id="create_date" name="create_date" readonly="readonly" value="" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
	<tr>
		<td class="form_title">备注：</td>
		<td class="form_input"><textarea name="remark" cols="50" rows="5" id="remark"></textarea></td>
	</tr>
	<tr>
	  <td class="form_title">增加产品</td>
	  <td class="form_input"><table width="340" border="0" cellpadding="2" cellspacing="1" class="listLogo" id="MGoodsPanel">
	    <tr>
	      <td>产品代码</td>
	      <td>产品名称</td>
          <td>重量</td>
	      <td>计量单位</td>
	      <td>订购数量</td>
	      <td><input type="button" name="button" id="button" value="增加产品" onClick="selectGoods()"></td>
          </tr>
      </table></td>
    </tr>
</table>
</form>
</body>
</html>
